package com.luyou.tianditu;


import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.setting.dialect.Props;
import com.alibaba.fastjson2.JSON;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * @author 28336
 * @version 1.0
 * Create by 2024/1/3 9:49
 */
public class SearchApi {

     private static final String apiKey;
     private static final String apiUrl;
     private static final Props props;

     static {
          props = new Props("config.properties");
          apiUrl = props.getStr("tianditu.api.url");
          apiKey = props.getStr("tianditu.api.key");
     }

     public static void main(String[] args) {
          surroundingSearch();
     }


     private static void surroundingSearch(){
          Map<String, Object> paramMap = new HashMap<>();
          String url = apiUrl +"/v2/search";
          SearchRequest searchRequest = new SearchRequest();
          searchRequest.setKeyWord("公交站");
          searchRequest.setQueryRadius("2000");
          searchRequest.setPointLonlat("114.425384,30.480069");
          searchRequest.setQueryType("3");
          searchRequest.setStart("0");
          searchRequest.setCount("10");
          searchRequest.setShow("1");

          paramMap.put("postStr", JSON.toJSONString(searchRequest));
          paramMap.put("type", "query");
          paramMap.put("tk", apiKey);
          HttpResponse execute = HttpRequest.get(url)
                  .form(paramMap).execute();
          System.out.printf(execute.body());
     }
}
